;This is the schnittstelle .... to xml files used in BLOCKWORLD

;  Prefix: BW_XML_
/*
BW_XML_TEXTURE_CREATE(xmldata)
BW_XML_SAVE(xmldata,"C:\test.xml")
exitapp
*/

BW_XML_ANIMATION_CREATE(byref xmldata){
global
	xpath_load(xmldata)
	xpath(xmldata,"/animations[+1]/text()")
}
BW_XML_ANIMATION_OPEN(byref xmldata,path){
global
	xpath_load(xmldata,path)
}




BW_XML_TEXTURE_CREATE(byref xmldata){
global
	xpath_load(xmldata)
	xpath(xmldata,"/textures[+1]/text()")
}

BW_XML_LOAD(byref xmldata,path){
global
	xpath_load(xmldata,path)
}

BW_XML_ANIMATION_ADD(byref xmldata,animationname,texturelist){
global
	xpath(xmldata,"/animations/animation[+1]/text()",texturename)
	index	:= xpath(xmldata,"/animations/animation/count()")
	xpath(xmldata,"/animations/animation[" index "]/name[+1]/text()",animationname)
	xpath(xmldata,"/animations/animation[" index "]/textures[+1]/text()",animationname)
	Loop, parse, texturelist, |
	{
		IF(A_LoopField != ""){
			xpath(xmldata,"/animations/animation[" index "]/textures/texture[+1]/text()",A_LoopField)
		}
	}
	return, index
}



BW_XML_TEXTURE_ADD(byref xmldata,texturename,texturerelpath){
global
	xpath(xmldata,"/textures/texture[+1]/text()",texturename)
	index	:= xpath(xmldata,"/textures/texture/count()")
	xpath(xmldata,"/textures/texture[" index "]/name[+1]/text()",texturename)
	xpath(xmldata,"/textures/texture[" index "]/path[+1]/text()",texturerelpath)
	return, index
}

BW_XML_TEXTURE_GET(byref xmldata,index,item){
global
	If item not in name,path
	{
		msgbox, 16,error, Unknown node %item% in TEXTURE_XML!
		return, 0
	}
return, xpath(xmldata,"/textures/texture[" index "]/" item "/text()")
}

BW_XML_TEXTURE_COUNT(byref xmldata){
global
	return, xpath(xmldata,"/textures/texture/count()")
}
;---------------------------------------------------------------
BW_XML_ANIMATION_COUNT(byref xmldata){
global
	return, xpath(xmldata,"/animations/animation/count()")
}
BW_XML_ANIMATION_TEXTURE_COUNT(byref xmldata,animation){
global
	return, xpath(xmldata,"/animations/animation[" animation "]/textures/texture/count()")
}
BW_XML_ANIMATION_GET(byref xmldata,animation,item){
global
return, xpath(xmldata,"/animations/animation[" animation "]/" item "/text()")
}

BW_XML_ANIMATION_TEXTURE_GET(byref xmldata,animation,texture){
global
return, xpath(xmldata,"/animations/animation[" animation "]/textures/texture[" texture "]/text()")
}


;---------------------------------------------------------------



BW_XML_SAVE(byref xmldata,path){
global
	xpath_save(xmldata, path)
}
